package com.winit.attachment.repository;

import com.winit.attachment.model.Attachment;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import javax.transaction.Transactional;
import java.util.List;

public interface AttachmentRepository extends CrudRepository<Attachment, String> {
    //    int updateBrd_idByAttachment_idIn(String brdId, List<String> attachmentIds);
    @Modifying
    @Transactional
    @Query(value = "update matrix_attachment ma set ma.attachment_owner_id = ?1, ma.attachment_is_del = ?3 where ma.attachment_id in ?2", nativeQuery = true)
    int updateOwnerRelation(String ownerId, List<String> attachmentIds, String isDel);

    @Modifying
    @Transactional
    @Query(value = "update matrix_attachment ma set ma.attachment_is_del = ?2 where ma.attachment_owner_id = ?1", nativeQuery = true)
    int updateIsDelOfAttachmentByOwnerId(String ownerId, String isDel);

    List<Attachment> findByAttachmentOwnerId(String ownerId);

    Attachment findByAttachmentIdAndAttachmentIsDel(String attachmentId, String attachmentIsDel);
}
